<%--
  Created by IntelliJ IDEA.
  User: 00
  Date: 2018/1/30
  Time: 18:54
  To change this template use File | Settings | File Templates.
--%>
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%@include file="/WEB-INF/jsp/comm/head.jsp"%>
    <title>Title</title>
</head>
<body>

<div class="container">
    <div class="">
        <button class="btn btn-info" onclick="prepareAdd()"><i class="glyphicon glyphicon-plus-sign"></i> 添加缺陷类型</button>
        <%--<button class="btn btn-info" onclick="prepareUpdate()"><i class="glyphicon glyphicon-plus-sign"></i> 修改用户</button>--%>
        <button class="btn btn-danger" onclick="del()"><i class="glyphicon glyphicon-remove-circle"></i> 删除用户</button>
    </div>
    <table id="table"
    data-toggle="table"
    data-url="${ctx}/sys/config/show"
    data-striped="true"
    data-pagination="true"
    data-side-pagination="server"
    data-page-size="4"
    data-page-list="[4,8,12,16,20]">
        <thead>
            <tr>
                <th data-checkbox="true"></th>
                <th data-field="configValueName">缺陷类型名称</th>
                <th data-field="isStart" data-formatter="fomStatus">状态（启用/未启用）</th>
                <th id="caozuo" data-events="events" data-formatter="formOpt">操作</th>
            </tr>
        </thead>
    </table>

    <%--新增--%>
    <div id="add">
        <form action="" class="form-horizontal">
                <div class="col-md-10">
                    <input type="hidden" name="configValueId" class="form-control">
                </div>
               <div class="form-group">
                   <label for="" class="col-md-3 control-label">缺陷类型名称:</label>
                   <div class="col-md-8">
                       <input type="text" name="configValueName" class="form-control">
                   </div>
               </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">启用状态:</label>
                    <div class="col-md-8">
                        <input type="radio" name="isStart" value="1" checked>启用
                        <input type="radio" name="isStart" value="0">不启用
                    </div>
                </div>
        </form>
    </div>

    <%--修改--%>
    <div id="update">
        <form action="" class="form-horizontal">


            <div class="col-md-10">
                <input type="hidden" name="id" class="form-control">
            </div>
            <div class="form-group">
                <label for="" class="col-md-3 control-label">缺陷类型名称:</label>
                <div class="col-md-8">
                    <input type="text" name="configValueName" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">启用状态:</label>
                <div class="col-md-8">
                    <input type="radio" name="isStart" value="1">启用
                    <input type="radio" name="isStart" value="0">不启用
                </div>
            </div>
        </form>
    </div>



</div>

<%@include file="/WEB-INF/jsp/comm/foot.jsp"%>
<script>
    function fomStatus(value,row){
        return value==1?"启用":"禁用";
    };

    /*新增方法*/
    $(function(){
        $("#add").dialog({
            title:"添加缺陷类型",
            btnName:"确定",
            btnBind:function () {
                var param=$("#add form").serialize();
                $.post("/sys/config/add",param,function (isOk) {
                    toastr.warning("信息提示",isOk);
                    $("#add").dialog("close");
                    $("#table").bootstrapTable("refresh");
                },'text',)
            }
        });
    });
    function prepareAdd() {
        $("#add form")[0].reset();
        $("#add").dialog("open")
    }






//    function prepareUpdate(){
//        var rows=$("#table").bootstrapTable("getSelections");
//        if(rows.length==0){
//            swal({
//                title:"信息提示",
//                text:"请选择一项修改",
//                type:"warning",
//                confirmButtonText:"确定"
//            });
//            return;
//        }
//        for(var name in rows[0]){
//            $("#update").find("[name="+name+"]").val(rows[0][name]);
//
//        }
//        $("#update").dialog("open");
//    }



    function formOpt(value,row){
        var edit='<button class="btn btn-info edit" ><i class="glyphicon glyphicon-plus-sign"></i> 修改用户</button> '
        var edit1=row["isStart"] == 1 ? ' <button class="btn btn-primary edit1">启用</button>' : '<button class="btn btn-danger edit1">未启用</button>'
        return  edit+edit1;
    }
    var events={
        "click .edit" :function (e,value,row){
            prepareUpdate(row);
        },
        "click .edit1" : function (e,value,row) {
            edit1(row);
        }
    };


    /**
     * 修改状态
     */

    function edit1(row){
        var isStart;
        if(row["isStart"]==1){
            isStart=0;
        }else{
            isStart=1;
        }
        $.post(ctx+"sys/config/ztupdate",{id:row["id"],isStart:isStart},function(isOk){
            toastr.warning("信息提示",isOk);
            $("#table").bootstrapTable("refresh");
        })
    }


    /*修改*/

   

    $(function(){
        $("#update").dialog({
            title:"修改用户",
            btnName:"确定",
            btnBind:function(){
                var param=$("#update form").serialize();
                $.post("/sys/config/update",param,function(isOk){
                    toastr.warning("信息提示",isOk);
                    $("#update").dialog("close");
                    $("#table").bootstrapTable("refresh");
                },'text');
            }
        });
    });

    function prepareUpdate(row){
        for(var name in row){
            if(name=="isStart"){
                $("#update").find("[name="+name+"][value="+row[name]+"]").attr("checked",true);
                continue;
            }
            $("#update").find("[name="+name+"]").val(row[name]);
        }
        console.info(row)
        $("#update").dialog("open");
    }


    /**
     * 删除用户
     */
    function del(){
        var arr=$("#table").bootstrapTable("getSelections")
        if(arr.length==0){
            swal({
                title:"信息提示",
                text:"请选择一项待删除！",
                type:"warning",
                showCancelButton:false,
                confirmButtonColor:"#DD6B55",
                confirmButtonText:"确定"
            });
            return;
        }
        swal({
            title:"确定要删除吗？",
            text:"该操作不可逆，请谨慎操作！",
            type:"warning",
            showCancelButton:true,
            confirmButtonColor:"#DD6B55",
            confirmButtonColor:"确定",
            cancelButtonText:"取消",
            closeOnConfirm:false,
            closeOnCancel:false
        }).then(function(){
            var parms=$(arr).map(function(){
                return "ids="+this.id;
            }).get().join("&");
            $.post("/sys/config/delete",parms,function(isOk){
                if(isOk=="1")
                    toastr.success("删除成功！");
                else
                    toastr.error("删除失败！");
                $("#table").bootstrapTable("refresh")
            })
        })
    }







</script>
</body>
</html>
